﻿using Microsoft.Net.Http.Headers;

namespace 日志的使用
{
    /// <summary>
    /// 通过实现接口使用自定义中间件
    /// 然后在容器中注入，并添加到管道中才能使用
    /// </summary>
    public class SelfMiddleUseInterface : IMiddleware
    {
        /// <summary>
        /// 获取当前请求的IP信息
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            // context.Items["Key1"] = "This is Middleware.Items";  //map 内共享
            Console.WriteLine(" SelfMiddleware Begiin");
            await next.Invoke(context);
            //Console.WriteLine("The Request Ip is " + context.Request.HttpContext.Connection.RemoteIpAddress);
            Console.WriteLine(" SelfMiddleware End");
        }
    }
}
